package hbase;

/**
 * @author Lu Ruotong
 * @date 2022/3/12 19:06
 */

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.*;

public class CreateTable {
    public static void main(String[] args) throws Exception {
        try {
            Configuration conf = HBaseConfiguration.create();                           //hbase 连接
            conf.set("hbase.zookeeper.quorum", "192.168.116.11");
            HBaseAdmin admin = new HBaseAdmin(conf);
//            HBaseAdmin 类作用：便于进一步实例化hbaseAPI
            HTableDescriptor table = new HTableDescriptor(TableName.valueOf("student"));

            HColumnDescriptor cf1 = new HColumnDescriptor("info");

            table.addFamily(cf1);

            admin.createTable(table);
//        it should be HTableDescriptor desc--admin 可与table连接
            System.out.println("=> HBase :: Table -- student");
//        if you create it repeat ,it shows TableExistsException
        } catch (Exception e) {
            System.out.println("table already exists");
        }
    }
}

